<template>
  <div class="school">
    <h2>学校名称：{{name}}</h2>
    <h2>学校地址：{{address}}</h2>
    <h2>收到的学生姓名:{{studentName}}</h2>
  </div>
</template>

<script>
export default {
    name:'School',
    data() {
        return {
            name:'上海交通大学',
            address:'上海',
            studentName:''
        }
    },
    mounted(){
      this.$bus.$on('hello',(data) => {
        console.log('school组件，接收到了data：'+data)
        this.studentName = data
      })
    },
    beforeDestroy(){
      //在使用傀儡的组件被销毁之前，一点要解绑事件
      this.$bus.$off('hello')
    }
}
</script>

<style lang="css" scoped>
.school{
    background-color: skyblue;
    padding: 5px;
}
</style>